home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Atari Mega Archive 1
/
Atari Mega Archive - Volume 1.iso
/
mint
/
editors
/
mjovesrc.zoo
/
mac.c
< prev
next >
Wrap
C/C++ Source or Header
|
1992-04-04
|
59KB
|
2,957 lines
/***************************************************************************
* This program is Copyright (C) 1986, 1987, 1988 by Jonathan Payne. JOVE *
* is provided to you without charge, and with no warranty. You may give *
* away copies of JOVE, including sources, provided that this notice is *
* included in all the files. *
***************************************************************************/
/* (C) 1986, 1987, 1988 Ken Mitchum. This code is intended only for use with Jove. */
#include "tune.h"
#ifdef MAC
#include <MacTypes.h>
#include "jove.h"
#include <QuickDraw.h>
#include <WindowMgr.h>
#include <FontMgr.h>
#include <ListMgr.h>
#include <EventMgr.h>
#include <ControlMgr.h>
#include <DialogMgr.h>
#include <ResourceMgr.h>
#include <ToolboxUtil.h>
#include <HFS.h>
#include <StdFilePkg.h>
#include <MenuMgr.h>
#include <pascal.h>
#include <errno.h>
#include <SegmentLdr.h>
#include "mac.h"
#include "termcap.h"
extern struct menu Menus[NMENUS];
private EventRecord the_Event;
private void SetBounds proto((void));
private void Set_std proto((void));
private void Reset_std proto((void));
private bool is_dir proto((char *));
private bool findtext proto((void));
/* keycodes (from Inside MacIntosh I-251). because of changes with
the MacPlus, there are some duplicate codes between cursor keys and
keypad keys. these can be deciphered by the corresponding character
codes, which are different. this table simply translates a keycode
into a character code that is appropriate. */
#define NOKEY (-1)
#define RET 0x0D
#define TAB 0x09
#define BACKSP 0x08
#define ENTERL NOKEY /* left enter key absent on MacPlus */
#define COMMAND NOKEY /* will be no translation anyway for these */
#define SHIFT NOKEY
#define CAPSLOCK NOKEY
#define OPTION NOKEY
#define PADDOT '.' /* PAD period */
#define PAD0 '0'
#define PAD1 '1'
#define PAD2 '2'
#define PAD3 '3'
#define PAD4 '4'
#define PAD5 '5'
#define PAD6 '6'
#define PAD7 '7'
#define PAD8 '8'
#define PAD9 '9'
#define LEFTCURS 'B' /* jove only, make like commands */
#define RIGHTCURS 'F'
#define UPCURS 'P'
#define DOWNCURS 'N'
#define PADENTER RET
#define PADMINUS '-'
#define CLEAR 0
private char nsh_keycodes[] = {
'a','s','d','f','h', /* 0 - 4 */
'g','z','x','c','v', /* 5 - 9 */
NOKEY,'b','q','w','e', /* 10 - 14 */
'r','y','t','1','2', /* 15 - 19 */
'3','4','6','5','=', /* 20 - 24 */
'9','7','-','8','0', /* 25 - 29 */
']','O','u','[','i', /* 30 - 34 */
'p',RET,'l','j','\'', /* 35 - 39 */
'k',';','\\',',','/', /* 40 - 44 */
'n','m','.',TAB,NOKEY, /* 45 - 49 */
'`',BACKSP,ENTERL,NOKEY,NOKEY, /* 50 - 54 */
COMMAND,SHIFT,CAPSLOCK,OPTION, NOKEY, /* 55 - 59 */
NOKEY,NOKEY,NOKEY,NOKEY,NOKEY, /* 60 - 64 */
PADDOT,RIGHTCURS,NOKEY,NOKEY,NOKEY, /* 65 - 69 */
LEFTCURS,CLEAR,DOWNCURS,NOKEY,NOKEY, /* 70 - 74 */
NOKEY,PADENTER,UPCURS,PADMINUS,NOKEY, /* 75 - 79 */
NOKEY,NOKEY,PAD0,PAD1,PAD2, /* 80 - 84 */
PAD3,PAD4,PAD5,PAD6,PAD7, /* 85 - 89 */
NOKEY,PAD8,PAD9
};
private char sh_keycodes[] = {
'A','S','D','F','H', /* 0 - 4 */
'G','Z','X','C','V', /* 5 - 9 */
NOKEY,'B','Q','W','E', /* 10 - 14 */
'R','Y','T','!','@', /* 15 - 19 */
'#','$','^','%','+', /* 20 - 24 */
'(','&','_','*',')', /* 25 - 29 */
'}','O','U','{','I', /* 30 - 34 */
'P',RET,'L','J','\'', /* 35 - 39 */
'K',';','|','<','?', /* 40 - 44 */
'N','M','>',TAB,NOKEY, /* 45 - 49 */
'~',BACKSP,ENTERL,NOKEY,NOKEY, /* 50 - 54 */
COMMAND,SHIFT,CAPSLOCK,OPTION, NOKEY, /* 55 - 59 */
NOKEY,NOKEY,NOKEY,NOKEY,NOKEY, /* 60 - 64 */
PADDOT,RIGHTCURS,NOKEY,NOKEY,NOKEY, /* 65 - 69 */
LEFTCURS,CLEAR,DOWNCURS,NOKEY,NOKEY, /* 70 - 74 */
NOKEY,PADENTER,UPCURS,PADMINUS,NOKEY, /* 75 - 79 */
NOKEY,NOKEY,PAD0,PAD1,PAD2, /* 80 - 84 */
PAD3,PAD4,PAD5,PAD6,PAD7, /* 85 - 89 */
NOKEY,PAD8,PAD9
};
/* tn.h Modified for variable screen size 11/21/87. K. Mitchum */
#define SCREENSIZE (wc->w_rows * ROWSIZE)
#define FONT monaco
#define TEXTSIZE 9
#define HEIGHT 11
#define WIDTH 6
#define DESCENT 2
#define TWIDTH CO * WIDTH
#define THEIGHT LI * HEIGHT
/* window specs */
#define SCROLLWIDTH 16 /* width of scroll bar control in pixels */
#define WINDWIDTH (wc->w_width - SCROLLWIDTH + 1) /* local coordinates */
#define WINDHEIGHT (wc->w_height) /* local coordinates */
#define MAXROW (LI - 1)
#define MAXCOL (CO - 1)
/* for keyboard routines */
#define MCHARS 32 /* must be power of two */
#define NMASK MCHARS (-1) /* circular buffer */
/***************************************************/
/* these normally reside in "tune.c" which we don't use */
char *CmdDb; /* see InitMac() */
char *p_tempfile = ".jrecXXX";
char *d_tempfile = ".joveXXX";
char *Joverc = ".joverc";
void putcurs(),curset(),putp(),dellines(),inslines();
private Rect LimitRect; /* bounds we can't move past */
struct wind_config {
int w_width; /* pixel width of the Mac window */
int w_height;
int w_rows; /* rows of characters which fit the window */
int w_cols;
} wc_std, wc_user, *wc;
private WindowPtr theScreen;
int
errno;
bool
Windchange,
EventCmd,
Keyonly,
Bufchange,
Modechange,
Macmode = OFF;
/* Initialization Routines. */
void
InitBinds()
{
struct cmd *c;
data_obj **p;
int i;
p = MainKeys;
for (i= 0; i < NCHARS; i++) {
c = (struct cmd *) *p;
c->c_map = F_MAINMAP;
c->c_key = i;
p++;
}
p = EscKeys;
for (i= 0; i < NCHARS; i++) {
c = (struct cmd *) *p;
c->c_map = F_PREF1MAP;
c->c_key = i;
p++;
}
p = CtlxKeys;
for (i= 0; i < NCHARS; i++) {
c = (struct cmd *) *p;
c->c_map = F_PREF2MAP;
c->c_key = i;
p++;
}
}
private WindowPtr window;
private Rect r;
private CursHandle cross;
void
InitEvents()
{
void InitSysMenu();
window = theScreen;
InitSysMenu();
SetRect(&r,window->portRect.left,
window->portRect.top,
window->portRect.right - SCROLLWIDTH,
window->portRect.bottom - SCROLLWIDTH);
cross = GetCursor(crossCursor);
}
void
MacInit()
{
char *gethome();
void tn_init();
tn_init();
getdir();
gethome(); /* before anyone changes it */
CmdDb = malloc(strlen(gethome()) + 10);
/* ??? better check for CmdDb == NULL -- DHR */
strcpy(CmdDb,gethome());
strcat(CmdDb,"/cmds.doc");
InitBinds();
}
/* dummy routines. */
int dummy() {}
SIGRESULT
(*signal(sig,func)) proto((int))
int sig;
SIGRESULT (*func) proto((int));
{
return &dummy;
}
void dorecover() {}
/* Surrogate unix-style file i/o routines for Jove. These replace the
routines distributed in the libraries. They work with Jove, but may
not be general enough for other purposes. */
#include <io.h>
#define NFILES 10
/* #define fsetup(p) { \
* (p).ioCompletion = 0; \
* (p).ioVRefNum = cur_vol; \
* (p).ioDirID = cur_dir; \
* (p).ioFVersNum = 0; \
* }
* #define isetup(p) {(p).ioCompletion = 0; (p).ioVRefNum = cur_vol;}
*/
private int cur_vol; /* Disk or volume number */
private long cur_dir; /* Directory number */
private int cur_vref; /* ugh.. Vref for volume + directory */
struct ftab {
int inuse; /* 0 = closed 1 = binary 2 = text*/
int refnum; /* Mac file reference number */
} ft[NFILES];
private void
fsetup(p)
HParmBlkPtr p;
{
byte_zero(p,sizeof(HParamBlockRec));
p->fileParam.ioVRefNum = cur_vol;
p->fileParam.ioDirID = cur_dir;
p->fileParam.ioFVersNum = 0;
}
private void
isetup(p)
HIOParam *p;
{
byte_zero(p,sizeof(HIOParam));
p->ioVRefNum = cur_vol;
}
/* Kludge to convert Macintosh error codes to something like Unix. */
private int
cvt_err(err) /* some of these don't make sense... */
int err;
{
switch(err) {
case noErr: errno = 0; return 0;
case dirFulErr:
case dskFulErr: errno = ENOSPC; break;
case nsvErr:
case mFulErr:
case tmfoErr:
case fnfErr:
default: errno = ENOENT; break;
case ioErr: errno = EIO; break;
case bdNamErr:
case opWrErr:
case paramErr: errno = EINVAL; break;
case fnOpnErr: /* dubious... */
case rfNumErr: errno = EBADF; break;
case eofErr: /* ditto */
case posErr: errno = ESPIPE; break;
case wPrErr: errno = EROFS; break;
case fLckdErr:
case permErr: errno = EACCES; break;
case fBsyErr: errno = EBUSY; break;
case dupFNErr: errno = EEX